<?php

namespace app\admin\dao;

use app\common\model\UserPower;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * UserPowerDao 数据访问对象
 * Class UserPowerDao
 * @package app\admin\dao
 * @method UserPower findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method UserPower insertActive(array $params, array $allow_field = [])
 * @method UserPower updateActive(UserPower $model, array $params, array $allow_field = [])
 * @method UserPower findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method UserPower updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(UserPower $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class UserPowerDao
{
    use DaoTrait;

    /**
     * @var UserPower
     */
    private $baseModel;

    /**
     * UserPowerDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = UserPower::class;
    }

    public function delete($pagePathId, $userId): void
    {
        UserPower::destroy(fn($query) => $query->where('pagePathId', $pagePathId)->where('userId', $userId), true);
    }

    public function insert($pagePathId, $userId): void
    {

        $params = [
            'pagePathId' => $pagePathId,
            'userId' => $userId,
        ];

        try {

            $this->insertActive($params);
        } catch (\Exception $exception) {

        }

    }
}
